#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/10/31 8:18
# @Author  : zhaowp1109
# @File    : login_api.py
# @Description :
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.api import deps
from app.schemas.base import RespDetailSchema
from app.models import LocalLanguage, LocalCurrency
from app.schemas.locale import LocalLanguageModel, LocalCurrencyModel
from app.core.exceptions import UnicornException


router = APIRouter()

@router.get("/get_language_currency_data", name="获取语言和币种数据")
async def read_data(db: Session = Depends(deps.get_db)):
    try:
        languages = db.query(LocalLanguage).all()
        currencies = db.query(LocalCurrency).all()
        language_data = [] if not languages else [LocalLanguageModel(**lang.__dict__) for lang in languages]
        currency_data = [] if not currencies else [LocalCurrencyModel(**currency.__dict__) for currency in currencies]
        locale_data = {
            "language_data": language_data,
            "currency_data": currency_data
        }
        return RespDetailSchema(data=locale_data)
    except Exception as e:
        raise UnicornException(name="api error")
        #RespDetailSchema(status_code=500, message=str(e))
